//
//  Number+Extension.swift
//  hkc
//
//  Created by wang shuguan on 2017/12/24.
//  Copyright © 2017年 wang shuguan. All rights reserved.
//

import UIKit
extension NumberFormatter{
    convenience init(style:NumberFormatter.Style) {
        self.init()
        self.numberStyle = style
    }
}
extension Int{
    var decimalDescription:String{
        get{
            return NumberFormatter(style: .decimal).string(for: self)!
        }
    }
    var percentDescription:String{
        get{
            return NumberFormatter(style: .percent).string(for: self)!
        }
    }
    var to2fDescription:String{
        get{
            return String(format: "%.2f", self)
        }
    }
}
extension Float{
    var decimalDescription:String{
        get{
            return NumberFormatter(style: .decimal).string(for: self)!
        }
    }
    var percentDescription:String{
        get{
            return NumberFormatter(style: .percent).string(for: self)!
        }
    }
    var to2fDescription:String{
        get{
            return String(format: "%.2f", self)
        }
    }
}
extension CGFloat{
    var decimalDescription:String{
        get{
            return NumberFormatter(style: .decimal).string(for: self)!
        }
    }
    var percentDescription:String{
        get{
            return NumberFormatter(style: .percent).string(for: self)!
        }
    }
    var to2fDescription:String{
        get{
            return String(format: "%.2f", self)
        }
    }
}
extension Double{
    var decimalDescription:String{
        get{
            return NumberFormatter(style: .decimal).string(for: self)!
        }
    }
    var percentDescription:String{
        get{
            return NumberFormatter(style: .percent).string(for: self)!
        }
    }
    var to2fDescription:String{
        get{
            return String(format: "%.2f", self)
        }
    }
}
extension Array where Element == Double{
    func sum() -> Element {
        var e:Element = 0
        for x in self{
            e = e + x
        }
        return e
    }
}
extension Array where Element == CGFloat{
    func sum() -> Element {
        var e:Element = 0
        for x in self{
            e = e + x
        }
        return e
    }
}

extension Array where Element == Float{
    func sum() -> Element {
        var e:Element = 0
        for x in self{
            e = e + x
        }
        return e
    }
}

extension Array where Element == Int{
    func sum() -> Element {
        var e:Element = 0
        for x in self{
            e = e + x
        }
        return e
    }
}
